package com.example.walletmodule.conrtoller;

import com.example.walletmodule.entity.ConsumptionDTO;
import com.example.walletmodule.entity.UserEntity;
import com.example.walletmodule.entity.WalletDetailsEntity;
import com.example.walletmodule.entity.WalletEntity;
import com.example.walletmodule.service.UserService;
import com.example.walletmodule.service.WalletDetailsService;
import com.example.walletmodule.service.WalletService;
import com.example.walletmodule.util.CommonResult;
import com.example.walletmodule.util.Constants;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;


/**
 * 钱包明细表
 *
 * @author wangqiao
 * @date 2023-02-21 16:40:42
 */
@RestController
@RequestMapping("walletdetails")
public class WalletDetailsController {
    @Resource
    private WalletDetailsService walletDetailsService;
    @Resource
    private UserService userService;

    /***
     * @method consumption
     * @author wangqiao
     * @date 2023/2/22 10:02
     * @description 消费xx元
     * @param consumptionDTO
     * @return CommonResult<Boolean>
     *
     */
    @PostMapping("/consumption")
    public CommonResult<Boolean> consumption(@RequestBody ConsumptionDTO consumptionDTO){
        // 判断支付密码
        UserEntity user = userService.getById(consumptionDTO.getUserId());
        if(!user.getUserPayPwd().equals(consumptionDTO.getUserPayPwd())){
            return CommonResult.fail(null, "支付密码错误，重新输入支付密码");
        }

        return walletDetailsService.comsuption(consumptionDTO);

    }

    @GetMapping("/queryWalletDetails")
    public CommonResult<List<WalletDetailsEntity>> queryWalletDetails(@RequestBody WalletDetailsEntity walletDetailsEntity){
        return walletDetailsService.queryWalletDetails(walletDetailsEntity);
    }

    /**
     * @method refundMoney
     * @author wangqiao
     * @date 2023/2/22 11:31
     * @description  退款接口
     * @param walletDetailsEntity
     * @return CommonResult<Boolean>
     *
     */
    @PostMapping("/refundMoney")
    public CommonResult<Boolean> refundMoney(@RequestBody ConsumptionDTO consumptionDTO){

        return walletDetailsService.refundMoney(consumptionDTO);
    }


}
